﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using DCTAccess.Business.Member;
using DCTLib.Common;
using Obout.Grid;

public partial class AdminZone_MemberList : System.Web.UI.Page
{
    private string Message
    {
        get { return lblError.Text; }
        set { lblError.Text = value; }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindDatagrid(0);
        }
    }


    /// <summary>
    /// Insert data in Obout
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void InsertRecord(object sender, GridRecordEventArgs e)
    {
        string insertText = "Function not available";
    }

    protected void DeleteRecord(object sender, GridRecordEventArgs e)
    {
        string insertText = "Function not available";
    }

    protected void UpdateRecord(object sender, GridRecordEventArgs e)
    {
        BindDatagrid(0);
    }


    //dung phan trang cho GridView
    protected void gvSearch_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        //MemberFilter filter = GetMemberForSearch();
        //ControlLoader.BindDatagrid(gvSearch, filter.GetMember(), e.NewPageIndex);
        BindDatagrid(e.NewPageIndex);

    }

    private void BindDatagrid(int pageIndex)
    {
        MemberFilter filter = GetMemberForSearch();
        Grid1.DataSource = filter.GetMember();
        Grid1.DataBind();
        DataTable dataTable = filter.GetMember();
        lblResult.Text = dataTable.Rows.Count + " kết quả tìm thấy";
    }

    private MemberFilter GetMemberForSearch()
    {
        MemberFilter filter = new MemberFilter();
        if (!string.IsNullOrEmpty(txtUsername.Text))
        {
            filter.FullName = txtUsername.Text;
        }

        if (!string.IsNullOrEmpty(txtFullName.Text))
        {
            filter.FullName = txtFullName.Text;
        }
        return filter;
    }

    protected void btnSearch_Click(object sender, EventArgs e)
    {
        try
        {
            MemberFilter filter = GetMemberForSearch();
            DataTable dataTable = filter.GetMember();
            if (!ValidationHelper.HasRow(dataTable))
            {
                lblResult.Text = "Không tìm thấy kết quả nào";
                //DatatableHelper.HasNoRow(dataTable, "FullName", gvSearch);
                Grid1.DataSource = filter.GetMember();
                Grid1.DataBind();
            }
            else
            {
                lblResult.Text = dataTable.Rows.Count + " kết quả tìm thấy";
                //Load du lieu vào GridView
                //ControlLoader.BindDatagrid(gvSearch, filter.GetMember(), 0);
                //Load du lieu vào GridView Obout
                Grid1.DataSource = filter.GetMember();
                Grid1.DataBind();

            }
        }
        catch
        {
            Message = "Có lỗi trong quá trình tìm kiếm";
        }
    }
}
